package com.enniswu.weitter.user.start;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.VideoView;

import com.enniswu.weitter.R;
import com.enniswu.weitter.base.BaseActivity;
import com.enniswu.weitter.widget.adapter.FragmentPagerAdapter;

import java.util.Arrays;

import butterknife.BindView;

public class StartActivity extends BaseActivity implements StartFragmentListener {

    @BindView(R.id.vv_start)
    VideoView vvStart;
    @BindView(R.id.vp_start)
    ViewPager vpStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager(),
                Arrays.asList(new LoginFragment(), new IndexFragment(), new RegisterFragment()));
        vpStart.setAdapter(adapter);
        vpStart.setCurrentItem(1);

        vvStart.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video_start));
        vvStart.start();
        vvStart.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                vvStart.start();
            }
        });
    }

    @Override
    public void changeItem(int position) {
        vpStart.setCurrentItem(position);
    }
}
